package com.t9;

/**
 * Created by xuyiwei on 2018/7/21.
 */
interface Cycle{
    void run();
}
interface CycleFactory{
    Cycle getCycle();
}
class Unicycle implements Cycle{
    @Override
    public void run() {
        System.out.println("Unicycle车轮在转动");
    }
}
class Bicycle implements Cycle{
    @Override
    public void run() {
        System.out.println("Bicycle车轮在转动");
    }
}
class Tricycle implements Cycle{
    @Override
    public void run() {
        System.out.println("Tricycle车轮在转动");
    }
}
class UnicycleFactory implements CycleFactory{

    @Override
    public Cycle getCycle() {
        return new Unicycle();
    }
}
class BicycleFactory implements CycleFactory{

    @Override
    public Cycle getCycle() {
        return new Bicycle();
    }
}

class TricycleFactory implements CycleFactory{

    @Override
    public Cycle getCycle() {
        return new Tricycle();
    }
}
public class E18 {
    public static void getCycle(CycleFactory f){
        Cycle cycle = f.getCycle();
        cycle.run();
    }

    public static void main(String[] args) {
        getCycle(new UnicycleFactory());
        getCycle(new BicycleFactory());
        getCycle(new TricycleFactory());
    }
}
